package com.gdcp.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;
//统一返回数据
@Data
public class Result {
    @ApiModelProperty(value = "状态码")
    private Integer code;
    @ApiModelProperty(value = "是否成功")
    private Boolean success;
    @ApiModelProperty("信息")
    private String message;
    @ApiModelProperty(value = "返回的数据")
    private Map<String,Object> data=new HashMap<>();

    private Result(){

    }
//    成功
    public static Result ok(){
        Result result = new Result();
         result.setSuccess(true);
         result.setCode(RestCode.SUCCESS.getCode());
         result.setMessage(RestCode.SUCCESS.getMessage());
         return result;
    }
//    错误
    public static Result error(){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(RestCode.COMMON_FAIL.getCode());
        result.setMessage(RestCode.COMMON_FAIL.getMessage());
        return result;
    }
 public  Result data(String msg,Object o){
        this.data.put(msg,o);
     return this;
 }
 public Result code(Integer code){
        this.code=code;
        return this;
 }

 public Result message(String msg){
        this.message=msg;
        return this;
 }

}
